package app.displayTree.special.sub {
	import app.displayTree.analyze.DisplayTreeAnalyzeSupport;
	import app.utils.SWFInfoTreeImageUtils;

	import copyengine.infoTree.meta.CESAnimationEachFrameInfoMeta;
	import copyengine.infoTree.meta.CESColourQuadMeta;
	import copyengine.infoTree.meta.CESDisplayObjectMeta;

	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;

	import org.as3commons.lang.StringUtils;

	public final class QuadColourSpecialSymbol extends SpecialSymbolHandleBasic {
        private var mShapeColour:uint;

        public function QuadColourSpecialSymbol() {
            super();
        }

        override protected function isCanHandleThisSpecialSymbolKey(_symbolKey:String):Boolean {
            return StringUtils.startsWithIgnoreCase(_symbolKey, "Quad_");
        }

        override protected function initialize(_symbolKey:String, _symbol:DisplayObject):void {
            mShapeColour = SWFInfoTreeImageUtils.cacheDisplayObjectToBitmapData(_symbol).getPixel(0, 0);
        }


        override protected function doGenerateSpecialSymbolMeta(_symbol:Sprite, _support:DisplayTreeAnalyzeSupport):CESDisplayObjectMeta {
            var quadMeta:CESColourQuadMeta = new CESColourQuadMeta();
            quadMeta.name = _symbol.name;

            var symbolRe:Rectangle = _symbol.getBounds(_symbol.parent);
            var frameInfo:CESAnimationEachFrameInfoMeta = new CESAnimationEachFrameInfoMeta();
            var frameMatrix:Matrix = new Matrix();
            frameMatrix.translate(symbolRe.left, symbolRe.top);
            frameInfo.setMatrix(frameMatrix);
            quadMeta.frameTransformMatrixArray.push(frameInfo);

            quadMeta.width = symbolRe.width;
            quadMeta.height = symbolRe.height;
            quadMeta.alpha = _symbol.alpha;

            quadMeta.quadColour = mShapeColour;

            return quadMeta;
        }


    }
}
